package org.administer.contaroller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.administer.dao.CrmShoppingDao;
import org.administer.dao.CrmStoreDao;
import org.administer.pojo.CrmService;
import org.administer.pojo.CrmShopping;
import org.administer.pojo.CrmStore;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/Shopping")
public class ShoppingController {
    @Autowired
    private CrmShoppingDao crmShoppingDao;
    @Autowired
    private CrmStoreDao crmStoreDao;
    @RequestMapping("/index")
    public String index() throws Exception{
        return "Shopping/index";
    }
    @RequestMapping("/list")
    @ResponseBody
    public Map<String,Object> list(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer limit, CrmShopping crmShopping) throws Exception{
        Map<String,Object> map = new HashMap<>();
        Page<CrmService> pager1 = PageHelper.startPage(page,limit);
        map.put("code",0);
        map.put("msg",null);
        map.put("data",crmShoppingDao.getlist(crmShopping));
        map.put("count",pager1.getTotal());
        return map;
    }
    @RequestMapping("/search")
    @ResponseBody
    public List<CrmStore> search() throws Exception{
        return crmStoreDao.getAll();
    }
    @RequestMapping("/add")
    @ResponseBody
    public Map<String,Object> add(CrmShopping crmShopping) throws Exception{
        Map<String,Object> map=new HashMap<>();
        crmShoppingDao.add(crmShopping);
        return map;
    }
    @RequestMapping("/update")
    @ResponseBody
    public Map<String,Object> update(CrmShopping crmShopping) throws Exception{
        Map<String,Object> map=new HashMap<>();
        crmShoppingDao.update(crmShopping);
        return map;
    }
    @RequestMapping("/del")
    @ResponseBody
    public Map<String,Object> del(Integer id) throws Exception{
        Map<String,Object> map=new HashMap<>();
        crmShoppingDao.del(id);
        return map;
    }
}
